Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-31955: Fixed incorrect string type check - use isinstance(value, basestring)… #4316

Merged
merged 13 commits into from
Nov 8, 2017

Conversation

PavelStishenko
Copy link

Fixed incorrect string type check. Previously if unicode string was passed as executable value it was considered not as string, but as list.

https://bugs.python.org/issue31955

Previous PR on this issue (#4296) was mistaken - for Python3 str is equivalent to basestring.

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@PavelStishenko
Copy link
Author

This PR is instead of PR #4296 . I agree, that this fix is necessary only for Python 2.

distutils.CCompiler.set_executables() method. Previously if unicode string
was passed as executable value it was considered not as string, but as list.
It caused TypeError: "coercing to Unicode: need string or buffer, list
found" at unixccompiler.py, line 122, in _compile().
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NEWS entries are read by end users who don't care much to details. I suggest to be much more concise. For example:

Fix CCompiler.set_executable() of distutils to handle properly Unicode strings.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@merwok
Copy link
Member

merwok commented Nov 7, 2017

Do you think you could add tests for set_executables in Lib/distutils/tests/test_ccompiler.py ?

@@ -24,6 +24,28 @@ def library_option(self, lib):

class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):

def test_set_executables_unicode(self):
class MyCCompiler(CCompiler):
executables = {'compiler':'', 'compiler_cxx':'', 'linker':''}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 8: {'compiler': '', 'compiler_cxx': '', 'linker': ''}

@@ -24,6 +24,28 @@ def library_option(self, lib):

class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):

def test_set_executables_unicode(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to test_set_executable(), since you test 3 types, not only Unicode.

compiler = MyCCompiler()

# set executable as list
compiler.set_executables(compiler = ['/usr/bin/env', 'OMPI_MPICC=clang', '/usr/bin/mpicc.openmpi'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 8: no space around = when passing keyword argument: set_executables(compiler=[...])


# set executable as list
compiler.set_executables(compiler = ['/usr/bin/env', 'OMPI_MPICC=clang', '/usr/bin/mpicc.openmpi'])
print(compiler.executables)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug prints please.

compiler.set_executables(compiler = ['/usr/bin/env', 'OMPI_MPICC=clang', '/usr/bin/mpicc.openmpi'])
print(compiler.executables)
self.assertEqual(len(compiler.executables['compiler']) == 3)
self.assertEqual(len(compiler.executables['compiler'][2]) == '/usr/bin/mpicc.openmpi')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, I dislike testing only one value. Please test:

self.assertEqual(compiler.executables['compiler'], ...) # fill the dots ;-)

# set executable as unicode string
compiler.set_executables(linker = u'/usr/bin/env OMPI_MPICXX=clang++ /usr/bin/mpicxx.openmpi')
self.assertEqual(len(compiler.executables['linker']) == 3)
self.assertEqual(len(compiler.executables['linker'][2]) == '/usr/bin/mpicxx.openmpi')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a Unicode string here as well.

@PavelStishenko
Copy link
Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@Haypo: please review the changes made to this pull request.

Copy link
Contributor

@eamanu eamanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

@PavelStishenko
Copy link
Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@Haypo: please review the changes made to this pull request.


# set executable as list
compiler.set_executables(compiler=['env', 'OMPI_MPICC=clang', 'mpicc'])
self.assertEqual(len(compiler.compiler), 3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the length became redundant with the following check and so should be removed.

'mpicxx'])

# set executable as unicode string
compiler.set_executables(linker=u'env OMPI_MPICXX=clang++ mpicxx')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use a different string, like "env OMPI_MPICXX=clang++ linker" or whatever different than the previous test.

@vstinner
Copy link
Member

vstinner commented Nov 8, 2017

The change now looks to me, but I have a last minor request, sorry!

@PavelStishenko
Copy link
Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@Haypo: please review the changes made to this pull request.

@vstinner
Copy link
Member

vstinner commented Nov 8, 2017

Hum, @Mazay0, it seems like you didn't sign the CLA. What is your bugs.python.org login? If you are Dee Mee, please fill your GitHub login in your bugs.python.org profile: click on "Your Details".
https://bugs.python.org/user27322

@PavelStishenko
Copy link
Author

If you are Dee Mee, please fill your GitHub login in your bugs.python.org profile: click on "Your Details".

Done!

@vstinner
Copy link
Member

vstinner commented Nov 8, 2017

Done!

I confirm: after removing the "CLA not signed" label, the bot added the green "CLA signed" label.

@vstinner vstinner merged commit 8494829 into python:2.7 Nov 8, 2017
@vstinner
Copy link
Member

vstinner commented Nov 8, 2017

Thanks @Mazay0 and congratulations for your first PR! 🎉

@eamanu
Copy link
Contributor

eamanu commented Nov 8, 2017

@Mazay0 congratulation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants